import React, { useEffect } from 'react';
import {
  Form,
  Modal,
  Grid,
  Input,
  InputNumber,
  TimePicker,
} from '@arco-design/web-react';
import * as Model from '@/services/model';
const { useForm } = Form;
const { Row, Col } = Grid;
interface DetailModalProps {
  pointInfo?: { x: number; y: number; d?: number; t?: number } | false;
  onCancel: () => void;
  onOk: (params: Model.Truck) => void;
}

export const DetailModal = (props: DetailModalProps) => {
  const [form] = useForm();

  useEffect(() => {
    if (props.pointInfo !== false) {
      form.setFieldsValue(props.pointInfo);
    }
  }, [props.pointInfo]);

  const submit = async () => {
    const res = await form.validate();
    if (res) {
      props.onOk(res);
    }
  };
  return (
    <Modal
      visible={props.pointInfo !== false}
      title="编辑矩阵"
      mountOnEnter
      unmountOnExit
      onCancel={props.onCancel}
      onOk={submit}
      alignCenter={false}
      okText="提交"
      cancelText="取消"
      style={{ width: 400 }}
    >
      <Form
        form={form}
        labelAlign="left"
        labelCol={{ span: 6 }}
        wrapperCol={{ span: 18 }}
      >
        <Form.Item field="x" hidden>
          <Input />
        </Form.Item>
        <Form.Item field="y" hidden>
          <Input />
        </Form.Item>
        <Row gutter={24}>
          <Col span={24}>
            <Form.Item label="距离" field="d" required>
              <Input addAfter="千米" placeholder="请输入距离" allowClear />
            </Form.Item>
          </Col>
          <Col span={24}>
            <Form.Item label="时间" field="t" required>
              <Input addAfter="小时" placeholder="请输入时间" allowClear />
            </Form.Item>
          </Col>
        </Row>
      </Form>
    </Modal>
  );
};
